package com.iot.service;

import com.iot.mapper.DTmenuMapper;
import com.iot.mapper.TmenuMapper;
import com.iot.pojo.MTmenu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class TmenuServiceImpl implements TmenuService {

    @Autowired
    private TmenuMapper mapper;

    @Autowired
    private DTmenuMapper dmapper;
    @Override
    public int getRecordCount(String sWhere) {
        return mapper.getRecordCount(sWhere);
    }

    @Override
    public int insert(MTmenu mTmenu) throws Exception {
        int count = 0;
        count = getRecordCount(" AND SNAME='" + mTmenu.getSNAME() + "'");
        if (count > 0)
            throw new Exception("该名称已存在");
        return mapper.insert(mTmenu);
    }

    @Override
    public void update(MTmenu mTmenu) throws Exception {
        int count = 0;
        count = getRecordCount(" AND SNAME='" + mTmenu.getSNAME() + "' AND MENU_ID!=" + mTmenu.getMENU_ID() + "");
        if (count > 0)
            throw new Exception("该名称已存在");
        mapper.update(mTmenu);
    }

    @Override
    public void deleteById(int id) {
        mapper.deleteById(id);
    }

    @Override
    public MTmenu single(Integer id) {
        return mapper.single(id);
    }

    @Override
    public List<MTmenu> fetch(String sWhere) {
        return mapper.fetch(sWhere);
    }


    @Override
    public List<MTmenu> fetchByPage(Map<String, Object> map) {
        return dmapper.fetchByPage(map);

    }


}
